Skip to content

Conversation

@rickhanlonii
Copy link
Member

@rickhanlonii rickhanlonii commented Jan 14, 2018

Summary

This PR fixes most test failures reported by Jest's new --detectLeaks feature

Note: I wasn't able to see any measurable difference in heap usage using --logHeapUsage so this probably isn't as big of a deal as it would seem, just good to fix if we can

Details

Now that detectLeaks works in Jest 22, I ran it on the React repo and found that ~110/130 tests report leaks. That number is approximate because some tests leak intermittently

After investigating the leaks, I found that 1 line accounted for ~100 of the leaks. Removing this line reduces the failures from ~110 to ~10.

It looks like assigning a function to any window attribute inside setupEnvironment will leak the Window after the test due to the setupEnvironment closure. I've filed a bug in Jest here

Testing

Running this command:

yarn test --detectLeaks

Before

After

Note: a good file to test this with which will reliably fail on master and work on this branch is invertObject-test.js. These test could be in env=node yet this like still leaks Window object:

yarn test --detectLeaks invertObject-test.js

});

// Mock for ReactART.
HTMLCanvasElement.prototype.getContext = () => ({});
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gaearon this was added in your commit here, do you happen to remember why it is necessary? I didn't see anything throwing without it

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty sure ReactART-test failed without it

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passed locally, let's see if it fails in CI

@gaearon gaearon merged commit 4f309f8 into facebook:master Jan 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants